//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CPNegativas.h"
#include "DMNegativas.h"
#include "DMCli.h"
#include "stDMCli.h"
#include "stDmNeg.h"
#include "DMFat.h"
#include "clipbrd.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Cadpad"
#pragma link "CGAUGES"
#pragma link "PHDS"
#pragma link "PHGridEd"
#pragma link "PHEdit"
#pragma link "PHLabel"
#pragma link "PHMemo"
#pragma link "PHSpdBut"
#pragma resource "*.dfm"
TCPNegativas1 *CPNegativas1;
//---------------------------------------------------------------------------
__fastcall TCPNegativas1::TCPNegativas1(TComponent* Owner)
 : TCadPad1(Owner)
{
 SomenteBrowse = true;
 DSNegativas->Tabela = DMNegativas1->TBNegativas;
 DSNegativas->IndiceNome = "DataEmissaoTipoNegativa";
 PHDS1->Tabela = DMCli1->TBCli;
}
//---------------------------------------------------------------------------
void __fastcall TCPNegativas1::PHDS1AfterOpen(TObject *Sender)
{
 stCli = (struct CLI*)PHDS1->Buffer;
}
//---------------------------------------------------------------------------
void __fastcall TCPNegativas1::DSNegativasAfterOpen(TObject *Sender)
{
 CadNeg = (struct NEGAT*)DSNegativas->Buffer;
}
//---------------------------------------------------------------------------
void __fastcall TCPNegativas1::FormDestroy(TObject *Sender)
{
 CPNegativas1 = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TCPNegativas1::FormShow(TObject *Sender)
{
 Left = Application->MainForm->Left+12;
 Width = Application->MainForm->ClientWidth-12;
 Top = Application->MainForm->Top+8;
 Height = Application->MainForm->ClientHeight-80;
 PHGridEdit1->Left = Panel2->Left + 8;
 PHGridEdit1->Top = Panel2->Top + 60;
 PHGridEdit1->Width = Panel2->Width - 14;
 PHGridEdit1->Height = Panel2->Height - 115;
 PHDS1->BuscaKeyBD("Identificador",IntToStr(vg.EmpresaAtual),true,true);
 PHDS1->Refresh(false);
 PHDS1->HabilitaCampo(CLI_IDENTIFICADOR,0,false,false);
 PHDS1->HabilitaCampo(CLI_NOME,0,false,false);
 PHDS1->HabilitaCampo(CLI_MUNICIPIO,0,false,false);
 PHDS1->HabilitaCampo(CLI_INSCFEDERAL,0,false,false);
}
//---------------------------------------------------------------------------
void __fastcall TCPNegativas1::DSNegativasBeforePost(TObject *Sender)
{
 strcpy(CadNeg->IdentificadorLink,PHDS1->GT(CLI_IDENTIFICADOR).c_str());
}
//---------------------------------------------------------------------------
void __fastcall TCPNegativas1::PHDS1AfterRead(TObject *Sender)
{
 DSNegativas->RangeIndice = "IdentificadorLink";
 DSNegativas->RangeStart = PHDS1->GT(CLI_IDENTIFICADOR);
 DSNegativas->RangeEnd = DSNegativas->RangeStart;
 DSNegativas->Range = true;
 DSNegativas->First();
}
//---------------------------------------------------------------------------
void __fastcall TCPNegativas1::AcessaSiteClick(TObject *Sender)
{
 if(DSNegativas->CountReg())
  {
   AnsiString Site = URL_Negativas();
   if(Trim(Site) != "")
    {
     Clipboard()->AsText = String(PHDS1->GV(CLI_INSCFEDERAL));
     ShellExecute(Handle,"Open",Site.c_str(),"","",SW_SHOWMAXIMIZED);
    }
  }  
}
//---------------------------------------------------------------------------
AnsiString __fastcall TCPNegativas1::URL_Negativas(void)
{
 AnsiString Retorno = "";
 PHDataSource *DSTpNeg = new PHDataSource(NULL);
 try
  {
   DSTpNeg->Name = "DSTpNeg";
   DSTpNeg->Tabela = DMNegativas1->TBTipoNegativas;
   DSTpNeg->Open(true);
   DSTpNeg->First();
   if(DSTpNeg->BuscaKeyBD(TIPNEG_SIGLA,DSNegativas->GT(NEGAT_TIPONEGATIVA),true,false))
    {
     Retorno = DSTpNeg->GT(TIPNEG_URL);
    }
  }
 __finally
  {
   DSTpNeg->Close();
   delete DSTpNeg;
  }
 return(Retorno);
}
//---------------------------------------------------------------------------
